package cn.jd.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.jd.pojo.Account;
import cn.jd.service.IAccountService;

@Controller//注册bean并且声明该类是一个控制器类

public class AccountController {
	@Autowired
	private IAccountService accountService;
	
	
	@RequestMapping("/login")
	//为方法配置映射路径
	
	public String login(Account acc,HttpSession session){
		System.out.println("username:"+acc.getUserName());
		System.out.println("password:"+acc.getPassword());
		System.out.println("用户向login方法发送请求");
		Account account=accountService.accountLogin(acc);
        if(account!=null){
        	System.out.println(acc.getNickName());
        	session.setAttribute("acc",account);
        	return "index";//  /index.jsp
        }
		
		//return "login";//  /login.jsp
        return "redirect:/login.html";
	}
	@RequestMapping("/goreg")
    public String reg(Account acc) {
        Account account = accountService.checkReg(acc.getUserName());
        if (account == null) {
            accountService.addOne(acc);
            return "regok";
        }
        return "regno";
    }

}
